/*全局常量配置文件 2021-4-1 cgq*/
const colorList = [
  "#39B3FF",
  "#47E0E0",
  "#7891D9",
  "#83D978",
  "#C7A530",
  "#FF8439",
];
class ecahrData {
  rechibang(data) {
    return {
      tooltip: {
        trigger: "axis",
        axisPointer: {
          type: "shadow",
        },
      },
      grid: {
        left: "0%",
        right: "0%",
        bottom: "7%",
        top: "7%",
      },
      xAxis: [
        {
          type: "category",
          data: data.xAxis,
          axisTick: {
            alignWithLabel: true,
          },
        },
      ],
      yAxis: [
        {
          show: false,
        },
      ],

      series: [
        {
          type: "bar",
          barWidth: "30px",
          label: {
            show: true,
            position: "top",
            formatter: "{b}",
            valueAnimation: true,
          },
          itemStyle: {
            normal: {
              color: (params) => {
                return colorList[params.dataIndex];
              },
            },
          },
          data: data.series,
        },
      ],
    };
  }

  zjlr(data) {
    const jhnkse = [];
    data.map((a) => {
      jhnkse.push((a / 10000).toFixed(0));
    });
    return {
      grid: {
        left: "0%",
        right: "0%",
        bottom: "8%",
        top: "8%",
      },
      xAxis: {
        type: "category",
        data: ["净超大", "净大单", "净中单", "净小单"],
      },
      yAxis: {
        type: "value",
      },
      series: [
        {
          barWidth: "40px",

          itemStyle: {
            normal: {
              color: (params) => {
                let jhse = "red";
                if (params.data < 0) {
                  jhse = "green";
                }
                return jhse;
              },
              label: {
                show: true,
                position: "top",
                formatter: " {c}万",
              },
            },
          },
          data: jhnkse,
          type: "bar",
        },
      ],
    };
  }
  GetUpDownData(data) {
    return {
      tooltip: {
        trigger: "axis",
        axisPointer: {
          type: "shadow",
        },
      },
      grid: {
        left: "0%",
        right: "0%",
        top: "8%",
        bottom: "3%",
        containLabel: true,
      },
      xAxis: [
        {
          type: "category",
          data: [
            "涨停",
            "涨停~5%",
            "5%~1%",
            "1%~0%",
            "平盘",
            "0%~-1%",
            "-1%~5%",
            "-5%~跌停",
            "跌停",
          ],
          axisTick: {
            alignWithLabel: true,
          },
        },
      ],
      yAxis: [
        {
          type: "value",
        },
      ],
      series: [
        {
          name: "涨跌统计",
          type: "bar",
          barWidth: "25px",
          data: data,
          label: {
            show: true,
            position: "top",
          },
          itemStyle: {
            normal: {
              color: (params) => {
                let jhse = "#E94848";
                if (params.dataIndex == 4) {
                  jhse = "#999";
                }
                if (params.dataIndex > 4) {
                  jhse = "#4DBF41";
                }
                return jhse;
              },
            },
          },
        },
      ],
    };
  }

  setDateLine(Data) {
    const upColor = "#ec0000";
    const upBorderColor = "#8A0000";
    const downColor = "#00da3c";
    const downBorderColor = "#008F28";
    // Each item: open，close，lowest，highest
    const data0 = splitData(Data);

    function splitData(rawData) {
      const categoryData = [];
      const values = [];
      for (let i = 0; i < rawData.length; i++) {
        categoryData.push(rawData[i].splice(0, 1)[0]);
        values.push(rawData[i]);
      }
      return {
        categoryData: categoryData,
        values: values,
      };
    }

    function calculateMA(dayCount) {
      const result = [];
      for (let i = 0, len = data0.values.length; i < len; i++) {
        if (i < dayCount) {
          result.push("-");
          continue;
        }
        let sum = 0;
        for (let j = 0; j < dayCount; j++) {
          sum += +data0.values[i - j][1];
        }
        result.push(sum / dayCount);
      }
      return result;
    }
    return {
      tooltip: {
        trigger: "axis",
        axisPointer: {
          type: "cross",
        },
      },
      legend: {
        data: ["日K", "5日均线", "10日均线", "20日均线", "30日均线"],
      },
      grid: {
        left: "5%",
        right: "5%",
        bottom: "10%",
      },
      xAxis: {
        type: "category",
        data: data0.categoryData,
        scale: true,
        boundaryGap: false,
        axisLine: {
          onZero: false,
        },
        splitLine: {
          show: false,
        },
        min: "dataMin",
        max: "dataMax",
      },
      yAxis: {
        scale: true,
        splitArea: {
          show: true,
        },
      },
      dataZoom: [
        {
          type: "inside",
          start: 50,
          end: 100,
        },
        {
          show: true,
          type: "slider",
          top: "90%",
          start: 50,
          end: 100,
        },
      ],
      series: [
        {
          name: "日K",
          type: "candlestick",
          data: data0.values,
          itemStyle: {
            color: upColor,
            color0: downColor,
            borderColor: upBorderColor,
            borderColor0: downBorderColor,
          },
          markPoint: {
            label: {
              formatter: function (param) {
                return param != null ? param.value + "" : "";
              },
            },
            data: [
              {
                name: "highest value",
                type: "max",
                valueDim: "highest",
              },
              {
                name: "lowest value",
                type: "min",
                valueDim: "lowest",
              },
              {
                name: "average value on close",
                type: "average",
                valueDim: "close",
              },
            ],
            tooltip: {
              formatter: function (param) {
                return param.name + "<br>" + (param.data.coord || "");
              },
            },
          },
          markLine: {
            symbol: ["none", "none"],
            data: [
              [
                {
                  name: "from lowest to highest",
                  type: "min",
                  valueDim: "lowest",
                  symbol: "circle",
                  symbolSize: 10,
                  label: {
                    show: false,
                  },
                  emphasis: {
                    label: {
                      show: false,
                    },
                  },
                },
                {
                  type: "max",
                  valueDim: "highest",
                  symbol: "circle",
                  symbolSize: 10,
                  label: {
                    show: false,
                  },
                  emphasis: {
                    label: {
                      show: false,
                    },
                  },
                },
              ],
              {
                name: "min line on close",
                type: "min",
                valueDim: "close",
              },
              {
                name: "max line on close",
                type: "max",
                valueDim: "close",
              },
            ],
          },
        },
        {
          name: "5日均线",
          type: "line",
          showSymbol: false,
          data: calculateMA(5),
          smooth: true,
          lineStyle: {
            opacity: 1,
            width: 1,
          },
        },
        {
          name: "10日均线",
          type: "line",
          showSymbol: false,
          data: calculateMA(10),
          smooth: true,
          lineStyle: {
            opacity: 1,
            width: 1,
          },
        },
        {
          name: "20日均线",
          type: "line",
          showSymbol: false,
          data: calculateMA(20),
          smooth: true,
          lineStyle: {
            opacity: 1,
            width: 1,
          },
        },
        {
          name: "30日均线",
          type: "line",
          showSymbol: false,
          data: calculateMA(30),
          smooth: true,
          lineStyle: {
            opacity: 1,
            width: 1,
          },
        },
      ],
    };
  }
}
export default ecahrData;
